package com.tornainbow;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author mrcrysl
 */
public class Processor extends Thread {
    // Define a logger for this class
    private static Logger logger = LoggerFactory.getLogger(Processor.class);
    
    // Define a Map to hold the properties and define each properties' default value
    public final ConcurrentMap<String,String> properties = new ConcurrentHashMap<>();
    
    // Define the required properties
    public static final String PROP_JMS_URL = "jms.url";
    public static final String PROP_JMS_SOURCE_QUEUE_NAME = "jms.source.queue.name";
    public static final String PROP_JMS_DESTINATION_QUEUE_NAME = "jms.destination.queue.name";
    
    // Define default values for the properties
    private static final String DEFAULT_JMS_URL = "failover://tcp://localhost:61616";
    private static final String DEFAULT_JMS_SOURCE_QUEUE_NAME = "TESTQUEUE_SOURCE";
    private static final String DEFAULT_JMS_DESTINATION_QUEUE_NAME = "TESTQUEUE_DESTINATION";
    
    public Processor() {
        properties.putIfAbsent(PROP_JMS_URL, DEFAULT_JMS_URL);
        properties.putIfAbsent(PROP_JMS_SOURCE_QUEUE_NAME, DEFAULT_JMS_SOURCE_QUEUE_NAME);
        properties.putIfAbsent(PROP_JMS_DESTINATION_QUEUE_NAME, DEFAULT_JMS_DESTINATION_QUEUE_NAME);
    }
    
    /**
     * Sets a property in the properties map
     * @param key The key of the property
     * @param value The value of the property
     */
    public void setProperty(String key, String value) {
        if (properties.replace(key, value) == null) {
            properties.putIfAbsent(key, value);
        }
        logger.debug("Setting property: {} = {}", key, value);
    }
    
    /**
     * Returns the value associated to the given property in the properties map
     * @param key The key that will be used to retrieve the value
     * @return The value associated with the given key
     */
    public String getProperty(String key) {
        return properties.get(key);
    }
    
    /**
     * Returns the name of the class
     * @return The name of the class
     */
    public String getProcessorName() {
        return this.getName();
    }
    
    @Override
    public void run() {}
}
